package com.easy.config;

import com.easy.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class EasyConfig implements WebMvcConfigurer {

    public static final String STATIC_PATH="/img/";
    public static final String STATIC_DIR="D:\\easyVue\\uploadfile\\";

    @Autowired
    LoginInterceptor loginInt;

    //静态资源访问
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler( STATIC_PATH+"**").addResourceLocations("file:"+STATIC_DIR);
    }

    /**
     * 配置拦截器  让拦截器生效
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(new LoginInterceptor());//       /a/234
        registry.addInterceptor(loginInt).addPathPatterns("/**")
                .excludePathPatterns("/dologin","/register","/userexcel","/checkcode","/img/**","/chartdata");
    }
}